package com.ifp.opengate.boot.validator.service;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.ifp.opengate.boot.bean.ValidateEntity;
import com.ifp.opengate.boot.bean.ValidatorForm;
import com.ifp.opengate.boot.validator.constants.ValidatorConstants;

@Component
public class EnumValValidateServiceImpl extends ValidateServiceImpl {

    @Override
    public ValidateEntity validateValue(ValidatorForm validatorForm, Object data) {
        if (StringUtils.isBlank(validatorForm.getCheckPattern())) {
            return null;
        }
        String[] enums = validatorForm.getCheckPattern().split("\\|\\|", -1);
        if (!ArrayUtils.contains(enums, data)) {
            return new ValidateEntity(ValidatorConstants.DEFAULT_ERROR_CODE, "不合法的参数值", data,
                validatorForm.getParamName());
        }
        return null;
    }
}